home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group19]VCL Source Professional / IvMlCtrl.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-08-31  |  14.5 KB  |  692 lines

  1. unit IvMlCtrl;
  2.  
  3. {$I IVMULTI.INC}
  4.  
  5. interface
  6.  
  7. uses
  8. {$IFDEF WIN32}
  9.   Windows,
  10. {$ELSE}
  11.   WinTypes, WinProcs,
  12. {$ENDIF}
  13.   Classes, Graphics, Controls, Menus, Forms, Stdctrls, ExtCtrls;
  14.  
  15. type
  16.   { Label }
  17.  
  18. {$IFNDEF IVBIDI}
  19.   TIvCustomLabel = class(TCustomLabel)
  20.   private
  21.   {$IFDEF WIN32}
  22.     {$IFNDEF VER110}
  23.     procedure DoDrawText(var rect: TRect; flags: Integer);
  24.     {$ENDIF}
  25.   {$ENDIF}
  26.  
  27.   protected
  28.     FLocale: Integer;
  29.  
  30.     procedure SetLocale(value: Integer);
  31.  
  32.   {$IFDEF VER110}
  33.     procedure DoDrawText(var rect: TRect; flags: Word); override;
  34.   {$ENDIF}
  35.   {$IFDEF WIN32}
  36.     procedure Paint; override;
  37.   {$ENDIF}
  38.  
  39.   public
  40.     constructor Create(owner: TComponent); override;
  41.  
  42.     property Locale: Integer read FLocale write SetLocale;
  43.   end;
  44. {$ENDIF}
  45.  
  46. {$IFDEF IVBIDI}
  47.   TIvLabel = class(TLabel)
  48.   end;
  49. {$ELSE}
  50.   TIvLabel = class(TIvCustomLabel)
  51.   published
  52.     property Align;
  53.     property Alignment;
  54.     property AutoSize;
  55.     property Caption;
  56.     property Color;
  57.     property DragCursor;
  58.     property DragMode;
  59.     property Enabled;
  60.     property FocusControl;
  61.     property Font;
  62.     property Locale stored False;
  63.     property ParentColor;
  64.     property ParentFont;
  65.     property ParentShowHint;
  66.     property PopupMenu;
  67.     property ShowAccelChar;
  68.     property ShowHint;
  69.     property Transparent;
  70.   {$IFDEF IVWIDE}
  71.     property Layout;
  72.   {$ENDIF}
  73.     property Visible;
  74.     property WordWrap;
  75.     property OnClick;
  76.     property OnDblClick;
  77.     property OnDragDrop;
  78.     property OnDragOver;
  79.     property OnEndDrag;
  80.     property OnMouseDown;
  81.     property OnMouseMove;
  82.     property OnMouseUp;
  83.   {$IFDEF WIN32}
  84.     property OnStartDrag;
  85.   {$ENDIF}
  86.   end;
  87. {$ENDIF}
  88.  
  89.   { Group box }
  90.  
  91. {$IFNDEF IVBIDI}
  92.   TIvCustomGroupBox = class(TCustomGroupBox)
  93.   protected
  94.     FLocale: Integer;
  95.  
  96.     procedure SetLocale(value: Integer);
  97.  
  98.   {$IFDEF WIN32}
  99.     procedure Paint; override;
  100.   {$ENDIF}
  101.  
  102.   public
  103.     constructor Create(owner: TComponent); override;
  104.  
  105.     property Locale: Integer read FLocale write SetLocale;
  106.   end;
  107. {$ENDIF}
  108.  
  109. {$IFDEF IVBIDI}
  110.   TIvGroupBox = class(TGroupBox)
  111.   end;
  112. {$ELSE}
  113.   TIvGroupBox = class(TIvCustomGroupBox)
  114.   published
  115.     property Align;
  116.     property Caption;
  117.     property Color;
  118.     property Ctl3D;
  119.     property DragCursor;
  120.     property DragMode;
  121.     property Enabled;
  122.     property Font;
  123.     property Locale stored False;
  124.     property ParentColor;
  125.     property ParentCtl3D;
  126.     property ParentFont;
  127.     property ParentShowHint;
  128.     property PopupMenu;
  129.     property ShowHint;
  130.     property TabOrder;
  131.     property TabStop;
  132.     property Visible;
  133.     property OnClick;
  134.     property OnDblClick;
  135.     property OnDragDrop;
  136.     property OnDragOver;
  137.     property OnEndDrag;
  138.     property OnEnter;
  139.     property OnExit;
  140.     property OnMouseDown;
  141.     property OnMouseMove;
  142.     property OnMouseUp;
  143.   {$IFDEF WIN32}
  144.     property OnStartDrag;
  145.   {$ENDIF}
  146.   end;
  147. {$ENDIF}
  148.  
  149.   { Radio box }
  150.  
  151. {$IFNDEF IVBIDI}
  152.   TIvCustomRadioGroup = class(TCustomRadioGroup)
  153.   protected
  154.     FLocale: Integer;
  155.  
  156.     procedure SetLocale(value: Integer);
  157.  
  158.   {$IFDEF WIN32}
  159.     procedure Paint; override;
  160.   {$ENDIF}
  161.  
  162.   public
  163.     constructor Create(owner: TComponent); override;
  164.  
  165.     property Locale: Integer read FLocale write SetLocale;
  166.   end;
  167. {$ENDIF}
  168.  
  169. {$IFDEF IVBIDI}
  170.   TIvRadioGroup = class(TRadioGroup)
  171.   end;
  172. {$ELSE}
  173.   TIvRadioGroup = class(TIvCustomRadioGroup)
  174.   published
  175.     property Align;
  176.     property Caption;
  177.     property Color;
  178.     property Columns;
  179.     property Ctl3D;
  180.     property DragCursor;
  181.     property DragMode;
  182.     property Enabled;
  183.     property Font;
  184.     property ItemIndex;
  185.     property Items;
  186.     property Locale stored False;
  187.     property ParentColor;
  188.     property ParentCtl3D;
  189.     property ParentFont;
  190.     property ParentShowHint;
  191.     property PopupMenu;
  192.     property ShowHint;
  193.     property TabOrder;
  194.     property TabStop;
  195.     property Visible;
  196.     property OnClick;
  197.     property OnDragDrop;
  198.     property OnDragOver;
  199.     property OnEndDrag;
  200.     property OnEnter;
  201.     property OnExit;
  202.   {$IFDEF WIN32}
  203.     property OnStartDrag;
  204.   {$ENDIF}
  205.   end;
  206. {$ENDIF}
  207.  
  208.   { List box }
  209.  
  210. {$IFNDEF IVBIDI}
  211.   TIvCustomListBox = class(TCustomListBox)
  212.   private
  213.     FLocale: Integer;
  214.  
  215.     procedure SetLocale(value: Integer);
  216.  
  217.   protected
  218.     procedure CreateParams(var Params: TCreateParams); override;
  219.  
  220.   public
  221.     constructor Create(owner: TComponent); override;
  222.  
  223.     property Locale: Integer read FLocale write SetLocale;
  224.   end;
  225. {$ENDIF}
  226.  
  227. {$IFDEF IVBIDI}
  228.   TIvListBox = class(TListBox)
  229.   end;
  230. {$ELSE}
  231.   TIvListBox = class(TIvCustomListBox)
  232.   published
  233.     property Align;
  234.     property BorderStyle;
  235.     property Color;
  236.     property Columns;
  237.     property Ctl3D;
  238.     property DragCursor;
  239.     property DragMode;
  240.     property Enabled;
  241.     property ExtendedSelect;
  242.     property Font;
  243.   {$IFDEF IVIME}
  244.     property ImeMode;
  245.     property ImeName;
  246.   {$ENDIF}
  247.     property IntegralHeight;
  248.     property ItemHeight;
  249.     property Items;
  250.     property Locale stored False;
  251.     property MultiSelect;
  252.     property ParentColor;
  253.     property ParentCtl3D;
  254.     property ParentFont;
  255.     property ParentShowHint;
  256.     property PopupMenu;
  257.     property ShowHint;
  258.     property Sorted;
  259.     property Style;
  260.     property TabOrder;
  261.     property TabStop;
  262.   {$IFDEF WIN32}
  263.     property TabWidth;
  264.   {$ENDIF}
  265.     property Visible;
  266.     property OnClick;
  267.     property OnDblClick;
  268.     property OnDragDrop;
  269.     property OnDragOver;
  270.     property OnDrawItem;
  271.     property OnEndDrag;
  272.     property OnEnter;
  273.     property OnExit;
  274.     property OnKeyDown;
  275.     property OnKeyPress;
  276.     property OnKeyUp;
  277.     property OnMeasureItem;
  278.     property OnMouseDown;
  279.     property OnMouseMove;
  280.     property OnMouseUp;
  281.   {$IFDEF WIN32}
  282.     property OnStartDrag;
  283.   {$ENDIF}
  284.   end;
  285. {$ENDIF}
  286.  
  287.   { Combo box }
  288.  
  289. {$IFNDEF IVBIDI}
  290.   TIvCustomComboBox = class(TCustomComboBox)
  291.   private
  292.     FLocale: Integer;
  293.  
  294.     procedure SetLocale(value: Integer);
  295.  
  296.   protected
  297.     procedure CreateParams(var Params: TCreateParams); override;
  298.  
  299.   public
  300.     constructor Create(owner: TComponent); override;
  301.  
  302.     property Locale: Integer read FLocale write SetLocale;
  303.   end;
  304. {$ENDIF}
  305.  
  306. {$IFDEF IVBIDI}
  307.   TIvComboBox = class(TComboBox)
  308.   end;
  309. {$ELSE}
  310.   TIvComboBox = class(TIvCustomComboBox)
  311.   published
  312.     property Style; {Must be published before Items}
  313.     property Color;
  314.     property Ctl3D;
  315.     property DragMode;
  316.     property DragCursor;
  317.     property DropDownCount;
  318.     property Enabled;
  319.     property Font;
  320.   {$IFDEF IVIME}
  321.     property ImeMode;
  322.     property ImeName;
  323.   {$ENDIF}
  324.     property ItemHeight;
  325.     property Items;
  326.     property Locale stored False;
  327.     property MaxLength;
  328.     property ParentColor;
  329.     property ParentCtl3D;
  330.     property ParentFont;
  331.     property ParentShowHint;
  332.     property PopupMenu;
  333.     property ShowHint;
  334.     property Sorted;
  335.     property TabOrder;
  336.     property TabStop;
  337.     property Text;
  338.     property Visible;
  339.     property OnChange;
  340.     property OnClick;
  341.     property OnDblClick;
  342.     property OnDragDrop;
  343.     property OnDragOver;
  344.     property OnDrawItem;
  345.     property OnDropDown;
  346.     property OnEndDrag;
  347.     property OnEnter;
  348.     property OnExit;
  349.     property OnKeyDown;
  350.     property OnKeyPress;
  351.     property OnKeyUp;
  352.     property OnMeasureItem;
  353.   {$IFDEF WIN32}
  354.     property OnStartDrag;
  355.   {$ENDIF}
  356.   end;
  357. {$ENDIF}
  358.  
  359. implementation
  360.  
  361. {$IFNDEF IVBIDI}
  362. uses
  363.   {$IFNDEF WIN32}
  364.   SysUtils,
  365.   {$ENDIF}
  366.   IvDictio, IvMulti;
  367.  
  368. { TIvCustomLabel }
  369.  
  370. constructor TIvCustomLabel.Create(owner: TComponent);
  371. begin
  372.   inherited Create(owner);
  373.   FLocale := 0;
  374. end;
  375.  
  376. procedure TIvCustomLabel.SetLocale(value: Integer);
  377. begin
  378.   if value <> FLocale then
  379.   begin
  380.     FLocale := value;
  381.     Invalidate;
  382.   end;
  383. end;
  384.  
  385. {$IFDEF WIN32}
  386.   {$IFDEF VER110}
  387. procedure TIvCustomLabel.DoDrawText(var rect: TRect; flags: Word);
  388.   {$ELSE}
  389. procedure TIvCustomLabel.DoDrawText(var rect: TRect; flags: Integer);
  390.   {$ENDIF}
  391. var
  392.   Text: String;
  393. begin
  394.   Text := GetLabelText;
  395.   if (Flags and DT_CALCRECT <> 0) and ((Text = '') or ShowAccelChar and
  396.     (Text[1] = '&') and (Text[2] = #0)) then Text := Text + ' ';
  397.   if not ShowAccelChar then
  398.     Flags := Flags or DT_NOPREFIX;
  399.   Canvas.Font := Font;
  400.  
  401. {$IFDEF IVPRO32}
  402.  if IvIsLocaleBidirectional(FLocale) then
  403.    Flags := Flags or DT_RTLREADING;
  404. {$ENDIF}
  405.  
  406. {$IFDEF IVWIDE}
  407.   if not Enabled then
  408.   begin
  409.     OffsetRect(Rect, 1, 1);
  410.     Canvas.Font.Color := clBtnHighlight;
  411.     DrawTextEx(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags, nil);
  412.     OffsetRect(Rect, -1, -1);
  413.     Canvas.Font.Color := clBtnShadow;
  414.     DrawTextEx(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags, nil);
  415.   end
  416.   else
  417.     DrawTextEx(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags, nil);
  418. {$ELSE}
  419.   if not Enabled then
  420.     Canvas.Font.Color := clGrayText;
  421.   DrawTextEx(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags, nil);
  422. {$ENDIF}
  423. end;
  424.  
  425. procedure TIvCustomLabel.Paint;
  426. const
  427.   Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
  428.   BidiAlignments: array[TAlignment] of Word = (DT_RIGHT, DT_LEFT, DT_CENTER);
  429.   WordWraps: array[Boolean] of Word = (0, DT_WORDBREAK);
  430. var
  431.   Rect: TRect;
  432.   DrawStyle: Integer;
  433. begin
  434.   with Canvas do
  435.   begin
  436.     if not Transparent then
  437.     begin
  438.       Brush.Color := Self.Color;
  439.       Brush.Style := bsSolid;
  440.       FillRect(ClientRect);
  441.     end;
  442.     Brush.Style := bsClear;
  443.     Rect := ClientRect;
  444.     DrawStyle := DT_EXPANDTABS or WordWraps[WordWrap];
  445. {$IFDEF IVPRO32}
  446.     if IvIsLocaleBidirectional(FLocale) then
  447.       DrawStyle := DrawStyle or BidiAlignments[Alignment]
  448.     else
  449. {$ENDIF}
  450.       DrawStyle := DrawStyle or Alignments[Alignment];
  451. {$IFDEF IVWIDE}
  452.     { Calculate vertical layout }
  453.     if Layout <> tlTop then
  454.     begin
  455.       DoDrawText(Rect, DrawStyle or DT_CALCRECT);
  456.       if Layout = tlBottom then
  457.         OffsetRect(Rect, 0, Height - Rect.Bottom)
  458.       else
  459.         OffsetRect(Rect, 0, (Height - Rect.Bottom) div 2);
  460.     end;
  461. {$ENDIF}
  462.     DoDrawText(Rect, DrawStyle);
  463.   end;
  464. end;
  465. {$ENDIF}
  466.  
  467.  
  468. { TIvCustomGroupBox }
  469.  
  470. constructor TIvCustomGroupBox.Create(owner: TComponent);
  471. begin
  472.   inherited Create(owner);
  473.   FLocale := 0;
  474. end;
  475.  
  476. procedure TIvCustomGroupBox.SetLocale(value: Integer);
  477. begin
  478.   if value <> FLocale then
  479.   begin
  480.     FLocale := value;
  481.     Invalidate;
  482.   end;
  483. end;
  484.  
  485. {$IFDEF WIN32}
  486. procedure TIvCustomGroupBox.Paint;
  487. var
  488. {$IFDEF IVPRO32}
  489.   w: Integer;
  490. {$ENDIF}
  491.   H, flags: Integer;
  492.   R: TRect;
  493. begin
  494.   with Canvas do
  495.   begin
  496.     Font := Self.Font;
  497.     H := TextHeight('0');
  498.     R := Rect(0, H div 2 - 1, Width, Height);
  499.     if Ctl3D then
  500.     begin
  501.       Inc(R.Left);
  502.       Inc(R.Top);
  503.       Brush.Color := clBtnHighlight;
  504.       FrameRect(R);
  505.       OffsetRect(R, -1, -1);
  506.       Brush.Color := clBtnShadow;
  507.     end else
  508.       Brush.Color := clWindowFrame;
  509.     FrameRect(R);
  510.     if Text <> '' then
  511.     begin
  512. {$IFDEF IVPRO32}
  513.       if IvIsLocaleBidirectional(FLocale) then
  514.         flags := DT_RTLREADING
  515.       else
  516. {$ENDIF}
  517.         flags := 0;
  518.  
  519.       R := Rect(8, 0, Width - 16, H);
  520.       DrawTextEx(
  521.         Handle,
  522.         PChar(Text),
  523.         Length(Text),
  524.         R,
  525.         flags or DT_LEFT or DT_SINGLELINE or DT_CALCRECT,
  526.         nil);
  527.  
  528.       Brush.Color := Color;
  529. {$IFDEF IVPRO32}
  530.       w := R.right - R.left;
  531.       if IvIsLocaleBidirectional(FLocale) then
  532.       begin
  533.         R.right := Width - 8;
  534.         R.left := R.right - w;
  535.       end;
  536. {$ENDIF}
  537.  
  538.       DrawTextEx(
  539.         Handle,
  540.         PChar(Text),
  541.         Length(Text),
  542.         R,
  543.         flags or DT_LEFT or DT_SINGLELINE,
  544.         nil);
  545.     end;
  546.   end;
  547. end;
  548. {$ENDIF}
  549.  
  550.  
  551. { TIvCustomRadioGroup }
  552.  
  553. constructor TIvCustomRadioGroup.Create(owner: TComponent);
  554. begin
  555.   inherited Create(owner);
  556.   FLocale := 0;
  557. end;
  558.  
  559. procedure TIvCustomRadioGroup.SetLocale(value: Integer);
  560. begin
  561.   if value <> FLocale then
  562.   begin
  563.     FLocale := value;
  564.     Invalidate;
  565.   end;
  566. end;
  567.  
  568. {$IFDEF WIN32}
  569. procedure TIvCustomRadioGroup.Paint;
  570. var
  571.   H, flags: Integer;
  572.   R: TRect;
  573. {$IFDEF IVPRO32}
  574.   w: Integer;
  575. {$ENDIF}
  576. begin
  577.   with Canvas do
  578.   begin
  579.     Font := Self.Font;
  580.     H := TextHeight('0');
  581.     R := Rect(0, H div 2 - 1, Width, Height);
  582.     if Ctl3D then
  583.     begin
  584.       Inc(R.Left);
  585.       Inc(R.Top);
  586.       Brush.Color := clBtnHighlight;
  587.       FrameRect(R);
  588.       OffsetRect(R, -1, -1);
  589.       Brush.Color := clBtnShadow;
  590.     end else
  591.       Brush.Color := clWindowFrame;
  592.     FrameRect(R);
  593.     if Text <> '' then
  594.     begin
  595. {$IFDEF IVPRO32}
  596.       if IvIsLocaleBidirectional(FLocale) then
  597.         flags := DT_RTLREADING
  598.       else
  599. {$ENDIF}
  600.         flags := 0;
  601.  
  602.       R := Rect(8, 0, Width - 16, H);
  603.       DrawTextEx(
  604.         Handle,
  605.         PChar(Text),
  606.         Length(Text),
  607.         R,
  608.         flags or DT_LEFT or DT_SINGLELINE or DT_CALCRECT,
  609.         nil);
  610.  
  611.       Brush.Color := Color;
  612. {$IFDEF IVPRO32}
  613.       w := R.right - R.left;
  614.       if IvIsLocaleBidirectional(FLocale) then
  615.       begin
  616.         R.right := Width - 8;
  617.         R.left := R.right - w;
  618.       end;
  619. {$ENDIF}
  620.  
  621.       DrawTextEx(
  622.         Handle,
  623.         PChar(Text),
  624.         Length(Text),
  625.         R,
  626.         flags or DT_LEFT or DT_SINGLELINE,
  627.         nil);
  628.     end;
  629.   end;
  630. end;
  631. {$ENDIF}
  632.  
  633. { TIvCustomListBox }
  634.  
  635. constructor TIvCustomListBox.Create(owner: TComponent);
  636. begin
  637.   inherited Create(owner);
  638.   FLocale := 0;
  639. end;
  640.  
  641. procedure TIvCustomListBox.SetLocale(value: Integer);
  642. begin
  643.   if value <> FLocale then
  644.   begin
  645.     FLocale := value;
  646. {$IFDEF IVPRO32}
  647.     RecreateWnd;
  648. {$ENDIF}
  649.   end;
  650. end;
  651.  
  652. procedure TIvCustomListBox.CreateParams(var Params: TCreateParams);
  653. begin
  654.   inherited CreateParams(params);
  655. {$IFDEF IVPRO32}
  656.   if IvIsLocaleBidirectional(FLocale) then
  657.     Params.ExStyle := Params.ExStyle or WS_EX_RIGHT or WS_EX_LEFTSCROLLBAR or WS_EX_RTLREADING;
  658. {$ENDIF}
  659. end;
  660.  
  661.  
  662. { TIvCustomComboBox }
  663.  
  664. constructor TIvCustomComboBox.Create(owner: TComponent);
  665. begin
  666.   inherited Create(owner);
  667.   FLocale := 0;
  668. end;
  669.  
  670. procedure TIvCustomComboBox.SetLocale(value: Integer);
  671. begin
  672.   if value <> FLocale then
  673.   begin
  674.     FLocale := value;
  675. {$IFDEF IVPRO32}
  676.     RecreateWnd;
  677. {$ENDIF}
  678.   end;
  679. end;
  680.  
  681. procedure TIvCustomComboBox.CreateParams(var Params: TCreateParams);
  682. begin
  683.   inherited CreateParams(params);
  684. {$IFDEF IVPRO32}
  685.   if IvIsLocaleBidirectional(FLocale) then
  686.     Params.ExStyle := Params.ExStyle or WS_EX_RIGHT or WS_EX_LEFTSCROLLBAR or WS_EX_RTLREADING;
  687. {$ENDIF}
  688. end;
  689. {$ENDIF}
  690.  
  691. end.
  692.